package net.xdclass.rbac_shiro.dao;

import net.xdclass.rbac_shiro.domain.Role;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * Created whit IntelliJ IDEA
 * User:杨骏杰
 * Date:2021/2/15
 * Time:20:29
 */
@Mapper
public interface RoleMapper {

    @Select("select ur.role_id as id," +
            "r.name as name," +
            "r.description as description " +
            "FROM user_role ur LEFT JOIN role r on r.id=ur.role_id" +
            " WHERE ur.user_id=#{userId}")
    @Results(
            value = {
                    @Result(id=true,property = "id",column = "id"),
                    @Result(property = "name",column = "name"),
                    @Result(property = "description",column = "description"),
                    @Result(property = "permissionList",column = "id",
                    many = @Many(select ="net.xdclass.rbac_shiro.dao.PermissionMapper.findPermissionListByRoleId",fetchType = FetchType.DEFAULT)
                    ),
            }
    )
    List<Role> findRoleListByUserId(@Param("userId")int userId);


}
